package com.yanqu.road.server.logic.recharge.limit;

import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.entity.mall.LimitBuyResult;
import com.yanqu.road.entity.player.UserInfo;
import com.yanqu.road.logic.config.ChannelConfig;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.PlayerModule;
import com.yanqu.road.server.manger.VipMgr;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.manger.player.UserMgr;
import com.yanqu.road.server.protocol.GameErrorCode;

public class TongBaoMallLimit extends BaseRMBMallLimit{

    public TongBaoMallLimit(long userId, MallInfo mallInfo) {
        super(userId, mallInfo);
    }

    @Override
    protected boolean isSystemUnLock() {
        //查看渠道配置
        int tongBaoBuySwitch = ChannelConfig.TONG_BAO_BUY_SWITCH;
        if (tongBaoBuySwitch == 0) {
            return false;
        }
        return true;
    }

    @Override
    protected LimitBuyResult buyCountLimit() {
        LimitBuyResult limitBuyResult = new LimitBuyResult();
        limitBuyResult.setLimitCount(Integer.MAX_VALUE);
        return limitBuyResult;
    }

    @Override
    protected int logicCheck() {

        //检测vip限购
        UserInfo userInfo = UserMgr.getUserInfo(userId);
        if (userInfo == null) {
            return GameErrorCode.E_MALL_LIMIT_BUY_VIP;
        }
        int vipLevel = VipMgr.getVipLv(userInfo.getVipExp());
        //不满足渠道vip限制
        if (vipLevel < ChannelConfig.TONG_BAO_BUY_VIP_LIMIT) {
            return GameErrorCode.E_MALL_LIMIT_BUY_VIP;
        }
        //不满足mall表限制
        if (vipLevel < mallInfo.getVipLimit()) {
            return GameErrorCode.E_MALL_LIMIT_BUY_VIP;
        }

        return 0;
    }
}
